package com.sky.handler;

import com.alibaba.fastjson.JSON;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import java.io.IOException;
import java.util.HashMap;

/**
 * @projectName: netty-cloud
 * @package: com.sky.handler
 * @className: MyLoginOutSuccessHandler
 * @author: zhl
 * @description: 实现本方法，替换security登录注销后自动跳转页面的处理方式
 * @date: 2024/4/25 14:39
 * @version: 1.0
 */
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        HashMap<String,Object> hashMap = new HashMap<>(16);
        hashMap.put("code",200);
        hashMap.put("msg","success");
        hashMap.put("data","注销成功");
        String json = JSON.toJSONString(hashMap);

        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(json);
    }
}
